﻿#region Usings

using System;
using System.Linq;
using System.Web.Mvc;
using XPressify.Data;
using XPressify.Data.CompliedQueries;

#endregion

namespace XPressify.Controllers
{
    public class EmailController : BaseController
    {
        public ActionResult ConfirmRegistration(Guid id)
        {
            var user = Repository.AsQueryable<User>().SingleOrDefault(x => x.Id == id);
            if (user != null)
            {
                ViewBag.SiteName = "Xpressify";
                ViewBag.Password = user.Password;
                ViewBag.ActivationUrl =
                    new Uri(HttpContext.Request.Url, Url.Action("Activate", "User", new {id})).ToString();
                ViewBag.SiteUrl = "http://localhost:1234/";
            }


            return View();
        }

        public ActionResult ConfirmFriendship(Guid id)
        {
            var repo = Repository;
            var relationship = RelationshipCompiledQueries.GetRelationship(repo as Repository, id);
            if (relationship != null)
            {
                ViewBag.SiteName = "Xpressify";
                ViewBag.FriendName = relationship.BaseSubject.FullName;
                ViewBag.YourName = relationship.BaseSubject2.FullName;
                ViewBag.RelationshipId = relationship.Id;
                ViewBag.ConfirmFriendshipUrl =
                    new Uri(HttpContext.Request.Url, Url.Action("ConfirmRelationship", "User", new {id})).ToString();
                ViewBag.PostponeFriendshipUrl =
                    new Uri(HttpContext.Request.Url, Url.Action("PostponeRelationship", "User", new {id})).ToString();
                ViewBag.SiteUrl = "http://localhost:1234/";
            }

            return View();
        }

        public ActionResult ConfirmGroupInvitation(Guid id)
        {
            var repo = Repository;
            var relationship = RelationshipCompiledQueries.GetRelationship(repo as Repository, id);
            if (relationship != null)
            {
                ViewBag.SiteName = "Xpressify";
                ViewBag.UserName = relationship.BaseSubject.FullName;
                ViewBag.GroupName = relationship.BaseSubject2.FullName;
                ViewBag.RelationshipId = relationship.Id;
                ViewBag.ConfirmFriendshipUrl =
                    new Uri(HttpContext.Request.Url, Url.Action("ConfirmRelationship", "Group", new {id})).ToString();
                ViewBag.PostponeFriendshipUrl =
                    new Uri(HttpContext.Request.Url, Url.Action("PostponeRelationship", "Group", new {id})).ToString();
                ViewBag.SiteUrl = "http://localhost:1234/";
            }

            return View();
        }

        public ActionResult ConfirmEventInvitation(Guid id)
        {
            var repo = Repository;
            var relationship = RelationshipCompiledQueries.GetRelationship(repo as Repository, id);
            if (relationship != null)
            {
                ViewBag.SiteName = "Xpressify";
                ViewBag.UserName = relationship.BaseSubject.FullName;
                ViewBag.EventName = relationship.BaseSubject2.FullName;
                ViewBag.RelationshipId = relationship.Id;
                ViewBag.ConfirmFriendshipUrl =
                    new Uri(HttpContext.Request.Url, Url.Action("ConfirmRelationship", "Event", new {id})).ToString();
                ViewBag.PostponeFriendshipUrl =
                    new Uri(HttpContext.Request.Url, Url.Action("PostponeRelationship", "Event", new {id})).ToString();
                ViewBag.SiteUrl = "http://localhost:1234/";
            }

            return View();
        }

        public ActionResult ConfirmPageInvitation(Guid id)
        {
            var repo = Repository;
            var relationship = RelationshipCompiledQueries.GetRelationship(repo as Repository, id);
            if (relationship != null)
            {
                ViewBag.SiteName = "Xpressify";
                ViewBag.UserName = relationship.BaseSubject.FullName;
                ViewBag.PageName = relationship.BaseSubject2.FullName;
                ViewBag.RelationshipId = relationship.Id;
                ViewBag.ConfirmFriendshipUrl =
                    new Uri(HttpContext.Request.Url, Url.Action("ConfirmRelationship", "Page", new {id})).ToString();
                ViewBag.PostponeFriendshipUrl =
                    new Uri(HttpContext.Request.Url, Url.Action("PostponeRelationship", "Page", new {id})).ToString();
                ViewBag.SiteUrl = "http://localhost:1234/";
            }

            return View();
        }


        public ActionResult AccountActivated(Guid id)
        {
            var user = UserCompiledQueries.GetUser(Repository as Repository, id);
            if (user != null)
            {
                ViewBag.SiteName = "Xpressify";
                ViewBag.Password = user.Password;
                ViewBag.SiteUrl = "http://localhost:1234/";
            }

            return View();
        }

        public ActionResult ForgotPassword(Guid id)
        {
            var user = UserCompiledQueries.GetUser(Repository as Repository, id);
            if (user != null)
            {
                ViewBag.Password = user.Password;
                ViewBag.SiteUrl = "http://localhost:1234/";
            }
            return View();
        }
    }
}